package jacker.bit.price;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;


public class ReceiverTime extends BroadcastReceiver {
	
	public static long lastchecktime = 0L;

	@Override
	public void onReceive(Context ctx, Intent intent) {
		
		if(!PrefStore.isPriceNotify(ctx))
			return;
		
		UtilLog.d("Minute checking... "
				+UtilString.hm.format(System.currentTimeMillis()) );
		
		int freq = PrefStore.getFetchFreq(ctx);
		
		if(freq>0 && (System.currentTimeMillis()-lastchecktime)<freq*56*1000L){
			return ;
		}
		
		if(UtilAndroid.hasInternet(ctx, false)){
			
			ctx.startService(new Intent(ctx,ServiceCheckPrice.class));

			lastchecktime = System.currentTimeMillis();
			
		}else{
			UtilLog.d("No network "
					+UtilString.hm.format(System.currentTimeMillis()) );
		}
		
		
	}

}
